package org.apache.dubbo.demo.consumer.example.eg10;

import java.util.HashMap;
import java.util.Map;
import org.apache.dubbo.demo.example.eg10.DemoService;
import org.apache.dubbo.rpc.service.EchoService;
import org.apache.dubbo.rpc.service.GenericService;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Application {

  @Test
  public void testSimpleParam() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:example/eg10/applicationContext.xml");
    GenericService demoService = (GenericService) context.getBean("demoService");
    Object result = demoService
        .$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{"xufeng"});
    System.out.println("************************* result: " + result + " *************************");
  }

  @Test
  public void testObjectParam() {
    Map<String, Object> person = new HashMap<>();
    person.put("name", "xufeng");
    person.put("email", "909012366@qq.com");

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:example/eg10/applicationContext.xml");
    GenericService demoService = (GenericService) context.getBean("demoService");
    Object result = demoService
        .$invoke("sayHello", new String[]{"org.apache.dubbo.demo.example.eg10.Person"},
            new Object[]{person});
    System.out.println("************************* result: " + result + " *************************");
  }

  @Test
  public void testEcho() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:example/eg10/applicationContext-echo.xml");
    DemoService demoService = (DemoService) context.getBean("demoService");
    EchoService echoService = (EchoService) demoService;
    Object status = echoService.$echo("OK");
    System.out.println("************************* status: " + status + " *************************");
  }

}
